-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::fmt;
use std::fs;
None => inferred_bench_targets(layout)
};
+ if let Err(e) = unique_names_in_targets(&bins) {
+ bail!("found duplicate binary name {}, but all binary targets \
+ must have a unique name", e);
+ }
+
+ if let Err(e) = unique_names_in_targets(&examples) {
+ bail!("found duplicate example name {}, but all binary targets \
+ must have a unique name", e);
+ }
+
+ if let Err(e) = unique_names_in_targets(&benches) {
+ bail!("found duplicate bench name {}, but all binary targets must \
+ have a unique name", e);
+ }
+
+ if let Err(e) = unique_names_in_targets(&tests) {
+ bail!("found duplicate test name {}, but all binary targets must \
+ have a unique name", e)
+ }
+
// processing the custom build script
let new_build = project.build.as_ref().map(PathBuf::from);
}
}
+/// Will check a list of toml targets, and make sure the target names are unique within a vector.
+/// If not, the name of the offending binary target is returned.
+fn unique_names_in_targets(targets: &[TomlTarget]) -> Result<(), String> {
+ let values = targets.iter().map(|e| e.name()).collect::<Vec<String>>();
+ let mut seen = HashSet::new();
+ for v in values {
+ if !seen.insert(v.clone()) {
+ return Err(v);
+ }
+ }
+ Ok(())
+}
+
fn validate_library_name(target: &TomlTarget) -> CargoResult<()> {
match target.name {
Some(ref name) => {
"));
});
+
+test!(duplicate_binary_names {
+ let foo = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "qqq"
+ version = "0.1.0"
+ authors = ["A <a@a.a>"]
+
+ [[bin]]
+ name = "e"
+ path = "a.rs"
+
+ [[bin]]
+ name = "e"
+ path = "b.rs"
+ "#)
+ .file("a.rs", r#"fn main() -> () {}"#)
+ .file("b.rs", r#"fn main() -> () {}"#);
+
+ assert_that(foo.cargo_process("build"),
+ execs().with_status(101).with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ found duplicate binary name e, but all binary targets must have a unique name
+"));
+});
+
+test!(duplicate_example_names {
+ let foo = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "qqq"
+ version = "0.1.0"
+ authors = ["A <a@a.a>"]
+
+ [[example]]
+ name = "ex"
+ path = "examples/ex.rs"
+
+ [[example]]
+ name = "ex"
+ path = "examples/ex2.rs"
+ "#)
+ .file("examples/ex.rs", r#"fn main () -> () {}"#)
+ .file("examples/ex2.rs", r#"fn main () -> () {}"#);
+
+ assert_that(foo.cargo_process("build").arg("--example").arg("ex"),
+ execs().with_status(101).with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ found duplicate example name ex, but all binary targets must have a unique name
+"));
+});
+
+test!(duplicate_bench_names {
+ let foo = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "qqq"
+ version = "0.1.0"
+ authors = ["A <a@a.a>"]
+
+ [[bench]]
+ name = "ex"
+ path = "benches/ex.rs"
+
+ [[bench]]
+ name = "ex"
+ path = "benches/ex2.rs"
+ "#)
+ .file("benches/ex.rs", r#"fn main () {}"#)
+ .file("benches/ex2.rs", r#"fn main () {}"#);
+
+ assert_that(foo.cargo_process("bench"),
+ execs().with_status(101).with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+ found duplicate bench name ex, but all binary targets must have a unique name
+"));
+});